Skip to content

Feature: resource default config#3135

Closed
bpolaszek wants to merge 2 commits into
api-platform:masterfrom
bpolaszek:fix-3099
Closed

Feature: resource default config#3135
bpolaszek wants to merge 2 commits into
api-platform:masterfrom
bpolaszek:fix-3099

Conversation

@bpolaszek

@bpolaszek bpolaszek commented Oct 2, 2019

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #3099
License MIT

This PR introduces a defaults configuration as an implementation of #3099.

Dummy implementation
As discussed offline with @alanpoulain and @dunglas, the implementation has been thought to be as dummy as possible, i.e. any configurable property or attribute in @ApiResource (and even future ones) can be configured on a default basis.

This means this configuration is perfectly correct for all resources:

api_platform:
    defaults:
        attributes:
            mercure: true
            messenger: true

But this one too:

api_platform:
    defaults:
        description: foo

Which means unconfigured @ApiResources will have the same description. That doesn't make sense, but we assume it's up to the developer, not the implementation, to decide what makes sense and what doesn't.

Short-hand operations configuration aren't supported yet
This short-hand configuration:

api_platform:
    defaults:
        itemOperations: ["get"]
        collectionOperations: ["get"]

is currently normalized in a private method from another ResourceMetadataFactory with a higher priority. What are your recommendations to standardize it?

Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Metadata/Resource/Factory/DefaultConfigurationResourceMetadataFactory.php Outdated
Comment thread src/Metadata/Resource/Factory/DefaultConfigurationResourceMetadataFactory.php Outdated
@bpolaszek

Copy link
Copy Markdown
Contributor Author

As discussed offline with @dunglas, several issues may be raised with this approach:

  • Defaults should be flattened (no more attributes sublevel)
  • snake_case should be the used
  • Using a decorating service with a low priority may prevent it from having the right configuration, as some data is normalized before.
  • Some properties should indeed be prevented from having defaults, e.g. shortName.

I'll open another PR to reflect those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants